class weekDays{
    constructor() {
        //2020年放假日期，date:具体哪天放假，type:1表示放假，0表示调休;
        //这是公司接口返回的数据，接口就不暴露了。如果自己用网上接口遇到跨域问题，我使用webpack代理跨域做了一个小案例
        this.Days = [
            {date: '2022-01-01', type: '1'},
            {date: '2022-01-02', type: '1'},
            {date: '2022-01-03', type: '1'},
            {date: '2022-01-29', type: '0'},
            {date: '2022-01-30', type: '0'},
            {date: '2022-01-31', type: '1'},
            {date: '2022-02-01', type: '1'},
            {date: '2022-02-02', type: '1'},
            {date: '2022-02-03', type: '1'},
            {date: '2022-02-04', type: '1'},
            {date: '2022-02-05', type: '1'},
            {date: '2022-02-06', type: '1'},
            {date: '2022-04-02', type: '0'},
            {date: '2022-04-03', type: '1'},
            {date: '2022-04-04', type: '1'},
            {date: '2022-04-05', type: '1'},
            {date: '2022-04-24', type: '0'},
            {date: '2022-04-30', type: '1'},
            {date: '2022-05-01', type: '1'},
            {date: '2022-05-02', type: '1'},
            {date: '2022-05-03', type: '1'},
            {date: '2022-05-04', type: '1'},
            {date: '2022-05-07', type: '0'},
            {date: '2022-06-03', type: '1'},
            {date: '2022-06-04', type: '1'},
            {date: '2022-06-05', type: '1'},
            {date: '2022-09-10', type: '1'},
            {date: '2022-09-11', type: '1'},
            {date: '2022-09-12', type: '1'},
            {date: '2022-10-01', type: '1'},
            {date: '2022-10-02', type: '1'},
            {date: '2022-10-03', type: '1'},
            {date: '2022-10-04', type: '1'},
            {date: '2022-10-05', type: '1'},
            {date: '2022-10-06', type: '1'},
            {date: '2022-10-07', type: '1'},
            {date: '2022-10-08', type: '0'},
            {date: '2022-10-09', type: '0'},
        ]
    }
    //判断今天是不是上班，（返回节假日）
    isholiday(startDay,endDay,dayLength){
        let backDays = []
        let dateRange = this.getDays(startDay,endDay,dayLength)

        let HDay = this.Days.map(item =>{
            if(item.type == 1){
                return item.date
            }
        })
        let WDay = this.Days.map(item => {
            if (item.type == 0) {
                return item.date
            }
        })
        backDays = dateRange.map(item =>{
            let day = new Date(item).getDay().toString();
            return (HDay.includes(item))||(day == '0' || day == '6')&&!WDay.includes(item)?{day:item,showDay:item+'（'+'节假日'+'）',isHoliday:true}:{day:item,showDay:item,isHoliday:false}
        })
        return backDays
    }
    //判断今天是不是上班，（未返回节假日）
    isWeekend(startDay,endDay,dayLength){
        let backDays = []
        let dateRange = this.getDays(startDay,endDay,dayLength)

        backDays = dateRange.map((item, i) => {
            
            let day = new Date(item).getDay().toString();
            
            return (day != '0' && day != '6')?{day:item,showDay:item,isHoliday:false}:{day:item,showDay:item+'（'+'节假日'+'）',isHoliday:true}
        })

        return backDays
    }
    getDays(startDay,endDay,dayLength){
        let dateRange = []
        let nextDay = startDay
        let count = 0
        while (nextDay != endDay) {
            nextDay = this.nextDay(nextDay, 1);
            let pushDay = this.filterDay(nextDay)
            dateRange.push(pushDay)
            count++
            if (count == dayLength) {
                break
            }
        }
        return dateRange
    }
    nextDay(nextDay, num) {
        let backnextDay = new Date(new Date(nextDay).getTime() + 24 * 60 * 60 * 1000 * num)
        return backnextDay
    }
    addZero(val) {
        if (val < 10) {
            return '0' + val
        } else {
            return val
        }
    }
    filterDay(date) {
        let month = this.addZero(date.getMonth() + 1)
        let day = this.addZero(date.getDate())
        return date.getFullYear() + '-' + month + '-' + day
    }

}
var WeekDays = new weekDays()

export default WeekDays